package com.itheima.app.controller;

import com.itheima.app.manager.UserManager;
import com.itheima.domain.db.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
public class UserController {
    @Autowired
    UserManager userManager;

    @PostMapping("/user/save")
    public Long save(@RequestBody User user){
       return userManager.save(user);
    }

    @GetMapping("/user/findByMobile")
    public  User findByMobile(String mobile){
        return userManager.findByMobile(mobile);
    }

    //发送验证码
    @PostMapping("/user/login")
    public void sendCode(@RequestBody Map<String,String>map){
        //获取手机号
        String phone = map.get("phone");
        //调用方法实现操作
        userManager.sendCode(phone);
    }

    @PostMapping("/user/loginVerification")
    public ResponseEntity regAndLogin(@RequestBody Map<String,String>map){
        return  userManager.regAndLogin(map);
    }
}
